x = int(input())
prime = 0

if 1 <= x // 1000 <= 9:
    nx = [x // 1000, x // 100 % 10,x // 10 % 10,x % 10,x // 100,x // 10 % 100,x % 100,x // 10,x % 1000,x]
    nx.sort()
    for i in nx:
        p = 0
        if i != 1:
            for j in range(2,i):
                if i % j == 0:
                    p = 1
                    break
            if p == 0:
                prime = i
print(prime)